<template>
  <!-- 发布任务-->

  <div class="AddTask">
    <div class="side_1"></div>
    <span class="add_1">发布任务</span>
    <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Fh">返回</el-button>
    <div class="body">
      <div class="form_body">
        <el-form ref="form" :model="form" label-width="80px" class="el_form_add">
          <el-form-item label="任务主题" class="item">
            <el-input style="" v-model="form.title" ></el-input>
          </el-form-item>
          <el-form-item label="任务内容" class="item">
            <el-input style="" type="textarea" :autosize="{ minRows: 2, maxRows: 5}" v-model="form.main" ></el-input>
          </el-form-item>
          <el-form-item label="完成时间" class="item">
            <el-col :span="11">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="form.date"
                style="width: 100%;"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="任务类型" class="item">
            <el-radio-group v-model="form.type">
              <el-radio :label="1">一般任务</el-radio>
              <el-radio :label="2">紧急任务</el-radio>
              <el-radio :label="3">循环任务</el-radio>
              <el-radio :label="4">长期任务</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="接收人" class="item">
            <el-radio-group v-model="receiver">
              <el-radio
                v-for="item in receiverList"
                :label="item.id"
                :key="item.id"
                name="receiver"
              >{{item.name}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <!-- <el-form ref="form" :model="form" label-width="100px" class="el_form_add">
          <el-form-item label="任务主题" class="item">
            <el-input v-model="form.title" style="width:60%;"></el-input>
          </el-form-item>
          <el-form-item label="任务内容" class="item">
            <el-input v-model="form.content" style="width:60%;"></el-input>
          </el-form-item>
          <el-form-item label="任务类型" class="item">
            <el-radio-group v-model="value">
              <el-radio v-for="item in form.type" :label="item.value" :key="item.key">{{item.value}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="完成日期" class="item">
            <el-date-picker type="date" placeholder v-model="form.date" style="width:30%;"></el-date-picker>
          </el-form-item>
          <el-form-item label="接收人" class="item">
            <el-checkbox-group v-model="value1">
              <el-checkbox
                v-for="item in form.receiver"
                :label="item.value"
                :key="item.key"
                name="receiver"
              >{{item.value}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>-->
      </div>
    </div>
    <div class="btn_bottom">
      <el-button type="primary" size="medium" @click="queD">确定</el-button>
      <el-button type="info" size="medium" @click="Fh">返回</el-button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: 'MySearch',
  data () {
    return {
      Mark: 0,
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      receiverList: [{ name: "王晓", id: 1 }, { name: "刘萍", id: 2 },],
      receiver: 0,
      creater: 0,
      form: {
        title: '',
        main: '',
        date: '',
        type: 1,
        receiver: 0,
        creater: 0,
      }
    }
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
    this.getemployees();
  },
  methods: {
    //获取接收人
    getemployees () {
      var obj = { creater: this.creater };
      var objs = JSON.stringify(obj);

      axios(
        "/apis/MyCenter.asmx/GetData?index=1&jsondata=" + objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var list = JSON.parse(datas.string.__text);
        this.receiverList = list;
      })
    },
    //保存任务
    queD () {
      if (this.Mark == 0) {
        if (this.form.title == "") { this.$message.error("任务主题非空"); return }
        if (this.form.main == "") { this.$message.error("任务内容非空"); return }
        if (this.form.date == "") { this.$message.error("完成时间非空"); return }
        if (this.receiver == 0) { this.$message.error("请选择接收人"); return }
        var str = [];
        str.push({ title: this.form.title, main: this.form.main, date: this.form.date, type: this.form.type, receiver: this.receiver, creater: this.creater });
        var objs = JSON.stringify(str);
        let the = { index: 1, jsondata: objs };
        console.log(the)
        this.Mark=1;
        axios.post("/apis/MyCenter.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          //console.log(data)
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);
          } else {
            this.$message.error(list.tip);
          }
        })
      }
    },
    Fh () {
      window.history.go(-1);
    }
  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.AddTask .body {
  width: 98%;
  height: 600px;
  background-color: $white;
  margin-left: 10px;
  margin-top: 40px;
  overflow: hidden;
}
.side_1 {
  width: 5px;
  height: 16px;
  background-color: $Header_color;
  margin-left: 10px;
  margin-top: 30px;
}
.add_1 {
  margin-left: 20px;
  margin-top: -20px;
  float: left;
  font-size: 18px;
  font-weight: 400;
}
.btn_fanhui {
  margin-top: -20px;
  margin-right: 20px;
  float: right;
}
.AddTask .el_form_add {
  width: 60%;
  height: 80%;
  border: 1px solid rgb(238, 232, 232);
  margin: auto;
  // margin-top:40px;
}
.item {
  width: 90%;
  margin: 0 auto;
}
.form_body {
  margin-top: 50px;
}
.el-form-item {
  margin-top: 20px;
}
.btn_bottom {
  margin-top: 50px;
  margin-left: 45%;
}
</style>
